<?php
/*
	异步通知处理
*/
define('NOSESSION',true);
require '../../core/core.php';
set_exi(function($message='success',$type='success'){
    //如果存在错误，此处整理错误日志，后期完善
    if($type=='error'){
        $log=date('Y/m/d H:i:s');
        $log.="\t{$_SESSION['uniacid']}\t{$_SESSION['uid']}\t{$message}\n";
        file_put_contents('error_log.txt',$log,FILE_APPEND);
    }
    echo 'error';
    exit;
});
if($_POST){
    $log2=ijson_encode($_POST);
    file_put_contents('error_log.txt',$log2."\n",FILE_APPEND);
    $bodydata=json_decode($_POST['data'],true);
    $body=$bodydata['body'];
}else{
    $body= $_RQ;
	$log2=ijson_encode($body);
    file_put_contents('error_log.txt',$log2."\n",FILE_APPEND);
    $ishema=true;
}
file_put_contents('error_log.txt',$body['batchNo']."~~~~~~~~\n",FILE_APPEND);
$cash=pdo_get('core_member_cash',array('ordersn'=>trim($body['batchNo'])));
if(!$cash){
    exi('指定订单不存在！'.$body['batchNo'],'error');
}
$_SESSION['uniacid']=$cash['uniacid'];
$_SESSION['uid']=$cash['mid'];
$_SESSION['this']='custom';
$setting=plugin('jy_huiqi365')->plugin_setting('basic');
$resBody = $resJson['body'];
$sign = base64_decode($resJson['sign']);
$platPubKey=$setting['pripubkey'];
$check=openssl_verify($resBody, $sign, $platPubKey, OPENSSL_ALGO_SHA256);
if($check){
    if($body['remitResult']=='S'){
        pdo_update('core_member_cash',array('status'=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$cash['id']));
    }else{
		pdo_update('core_member_cash',array('status'=>2),array('uniacid'=>$_SESSION['uniacid'],'id'=>$cash['id']));
	}
	exi('SUCCESS','success');
}else{
    exi('签名校验失败！','error');
}